package com.ly.core.utils;
 

import lombok.Data;

@Data
public class ResponseData {
	private int code;
    private String msg;
    private Object data;

    public ResponseData() {

    }

    public ResponseData(Object data) {
        this.data = data;
    }

    public ResponseData(ResponseCode responseCode, Object data) {
        this.code = responseCode.getCode();
        this.data = data;
    }

    public ResponseData(ResponseCode responseCode, String msg) {
        this.code = responseCode.getCode();
        this.msg = msg;
    }
 
    public ResponseData(ResponseCode responseCode, String msg, Object data) {
        this.code = responseCode.getCode();
        this.msg = msg;
        this.data = data;
    }
    
    public ResponseData(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }
    

    public boolean isSuccess() {
    	return this.code == ResponseCode.SUCCESS.getCode();
    }

    public static ResponseData success(String msg, Object data) {
        return new ResponseData(ResponseCode.SUCCESS, msg, data);
    }

    public static ResponseData success(Object data) {
        return new ResponseData(ResponseCode.SUCCESS, data);
    }

    public static ResponseData success() {
        return new ResponseData(ResponseCode.SUCCESS, "操作成功");
    }

    public static ResponseData fail(String msg) {
        return new ResponseData(ResponseCode.FAIL, msg);
    }
    
    public static ResponseData fail(Object data) {
    	return new ResponseData(ResponseCode.FAIL, data);
    }

    public static ResponseData fail() {
        return new ResponseData(ResponseCode.FAIL, "错误");
    }

    public static ResponseData fail(ResponseCode responseCode, String msg) {
        return new ResponseData(responseCode, msg);
    }

    public static ResponseData notFound() {
        return new ResponseData(ResponseCode.NOT_FOUND, "找不到资源");
    }
    
    public static ResponseData notLogin() {
    	return new ResponseData(999, "请登录");
    }

    public static Object badArgument(){
        return fail(ResponseCode.BAD_ARGUMENT, "参数不对");
    }


    public static Object badArgumentValue(){
        return fail(ResponseCode.BAD_ARGUMENT_VALUE, "参数值不对");
    }


    public static Object serious(){
        return fail(ResponseCode.SERIOUS, "系统内部错误");
    }

    public static Object unsupport(){
        return fail(ResponseCode.UN_SERIOUS, "业务不支持");
    }

}
